package com.jing.qq.qq;


import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends AppCompatActivity {

    private Button loginBtn;
    private EditText useridEt;
    private EditText passwdEt;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        loginBtn = (Button)findViewById(R.id.login_btn_login);
        useridEt = (EditText)findViewById(R.id.login_edit_account);
        passwdEt = (EditText)findViewById(R.id.login_edit_pwd);

        initListener();
    }

    private void initListener() {
        loginBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent = new Intent(LoginActivity.this,MessageListActivity.class);
                //startActivity(intent);

                String userId =  useridEt.getText().toString();
                String passwd = passwdEt.getText().toString();
                new Thread(new UserRunnable(userId,passwd,LoginActivity.this)).start();
            }
        });
    }

//go to register
    public void regedit(View view) {
        Intent intent = new Intent("register");
        startActivityForResult(intent,7);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==7&&resultCode==7){
            useridEt.setText(data.getStringExtra("uid"));
            passwdEt.setText(data.getStringExtra("pwd"));
        }
    }
}
